package code.c02_list.cdLinkList;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/9/26 19:54
 * @package code.c02_list.cdLinkList
 * @description 有两个双向链表A和B，将B的元素依次合并到A 中，合并后A仍然为一个循环双链表，并求算法的时间复杂度
 */

public class Exam_2_23 {
    public static CDLinkListClass<Integer> comb(CDLinkListClass<Integer> A, CDLinkListClass<Integer> B){
        DLinkNode<Integer> ta = A.dhead.prior;
        DLinkNode<Integer> tb = B.dhead.prior;
        // 将B的首结点 链接到 A的尾结点的下一个结点
        ta.next = B.dhead.next;
        B.dhead.next.prior = ta;
        tb.next=A.dhead;
        A.dhead.prior = tb;
        return A;
    }

    public static void main(String[] args) {
        Integer[] a = {1,4,5,5,6,67,43};
        Integer[] b = {5,5,5,6,4,343,3,23};

        CDLinkListClass<Integer> A = new CDLinkListClass<>();
        A.createListR(a);

        CDLinkListClass<Integer> B = new CDLinkListClass<>();
        B.createListR(b);

        CDLinkListClass<Integer> comb = comb(A, B);
        System.out.println(comb.toString());
    }
}
